package com.graduate.cec.controller;

import com.graduate.cec.common.JsonPage;
import com.graduate.cec.common.JsonResult;
import com.graduate.cec.pojo.dto.CommentSimpleDTO;
import com.graduate.cec.pojo.dto.UserSimpleDTO;
import com.graduate.cec.pojo.entity.Comment;
import com.graduate.cec.pojo.entity.User;
import com.graduate.cec.pojo.vo.CommentSimpleVO;
import com.graduate.cec.pojo.vo.CommentVO;
import com.graduate.cec.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/comment",produces = "application/json;charset=utf-8")
@Api(tags = "评论管理")
public class CommentController {
    @Resource
    private CommentService commentService;
    /****************        增       ******************************************************************/
    @GetMapping("/insert-comment")
    @ApiOperation("增加评论")
    public JsonResult<Void> insertComment(Comment comment){
        commentService.insertComment(comment);
        log.info("comment:{}",comment);
        return JsonResult.ok("插入成功");
    }



    /****************        删       ******************************************************************/
    @GetMapping("/delete-by-key")
    @ApiOperation("通过主键删除评论")
    public JsonResult<Void> deleteByKey(Long ids){
        log.info("ids:{}", ids);
        commentService.deleteByKey(ids);
        return JsonResult.ok("删除成功");
    }

    @GetMapping("/delete-by-keys/{ids}")
    @ApiOperation("通过主键删除评论")
    public JsonResult<Void> deleteByKeys(@PathVariable("ids") List<Long> ids){
        log.info("ids:{}", ids);
        commentService.deleteByKeys(ids);
        return JsonResult.ok("删除成功");
    }


    /****************        改       ******************************************************************/
    @PostMapping("/update-by-key")
    @ApiOperation("通过主键修改评论内容")
    public JsonResult<Void> updateByKey(@RequestBody Comment comment){
        log.info("comment:{}",comment);
        commentService.updateByKey(comment);
        return JsonResult.ok("修改成功");
    }


    /****************        查        ******************************************************************/

    /**
     * 查询所有列表
     * @return JsonResult<List<CommentVO>>
     */
    @GetMapping("/get-comment-by-id")
    @ApiOperation("查询评论通过id")
    public JsonResult<List<CommentVO>> getCommentById(Long id){
        return JsonResult.ok("查询成功",commentService.getCommentById(id));
    }


    /**
     * 查询所有列表
     * @return JsonResult<List<CommentVO>>
     */
    @GetMapping("/get-all-list")
    @ApiOperation("查询全部列表")
    public JsonResult<List<Comment>> getAllList(){
        return JsonResult.ok("查询成功",commentService.getAllList());
    }


    @GetMapping("/get-list-by-example")
    @ApiOperation("通过一定条件查找列表")
    public JsonResult<JsonPage<Comment>>getListByExample(CommentSimpleDTO commentSimpleDTO){
        return JsonResult.ok("查询成功",commentService.getListByExample(commentSimpleDTO));
    }


    @GetMapping("/get-list")
    @ApiOperation("通过一定条件查找列表")
    public JsonResult<JsonPage<CommentSimpleVO>>getList(CommentSimpleDTO commentSimpleDTO){
        return JsonResult.ok("查询成功",commentService.getList(commentSimpleDTO));
    }

}
